package pack.findthewords;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class Packs extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.packs);

	final TextView tipTv=(TextView) findViewById(R.id.pack_tip);
	int r=Utils.getRandForTip();
	final String urlTip=Utils.LOOKUP_TIPS_URLS[r];
	tipTv.setText(getResources().getString(Utils.LOOKUP_TIPS[r]));
	tipTv.setOnClickListener(new View.OnClickListener() {
	    @Override
	    public void onClick(View v) {
		Intent i=new Intent(Intent.ACTION_VIEW, Uri.parse(urlTip));
		startActivity(i);
	    }
	});

	initButtons();
    }

    private void initButtons() {
	Button btnClassic=(Button) findViewById(R.id.pack_btn_lvl_classic);
	Button btn2014=(Button) findViewById(R.id.pack_btn_lvl_2014);
	Button btnMore=(Button) findViewById(R.id.pack_btn_more);
	btnClassic.setOnClickListener(new View.OnClickListener() {
	    @Override
	    public void onClick(View v) {
		Intent intent=new Intent(Packs.this, Toc.class);
		startActivity(intent);
	    }
	});
	btn2014.setOnClickListener(new View.OnClickListener() {
	    @Override
	    public void onClick(View v) {
		Intent intent=new Intent(Packs.this, Toc2014.class);
		startActivity(intent);
	    }
	});
	btnMore.setOnClickListener(new View.OnClickListener() {
	    @Override
	    public void onClick(View v) {
		showNextDialog();
	    }
	});
    }

    private void showNextDialog() {
	new AlertDialog.Builder(this).setMessage(getResources().getString(R.string.pack_next_text))
	    .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
		@Override
		public void onClick(DialogInterface dialog, int which) {
		    dialog.cancel();
		}
	    }).show();
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
	// Inflate the menu; this adds items to the action bar if it is present.
	getMenuInflater().inflate(R.menu.opt_menu_gen, menu);
	return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
	switch (item.getItemId()) {
	    case R.id.opt_vote:
		Intent ii=new Intent(Intent.ACTION_VIEW, Uri.parse(Utils.MARKET_URL));
		startActivity(ii);
		return true;
	    case R.id.opt_back:
		finish();
		return true;
		/*
		 * case R.id.opt_adfree: Intent iii=new Intent(Intent.ACTION_VIEW,
		 * Uri.parse(Utils.MARKET_URL_NOADS)); startActivity(iii); return true; case
		 * R.id.opt_info: Intent iiii=new Intent(HowTo.this, Info.class);
		 * startActivity(iiii); return true;
		 */
	    default:
		return super.onOptionsItemSelected(item);
	}
    }

}
